package com.fjwt.gz.mgr.ctrl.score.stat.export;

import com.fjwt.gz.db.dto.StatScoreRecordDTO;
import com.fjwt.gz.db.entity.SysExportTaskEntity;
import com.fjwt.gz.db.vo.StatScoreRecordVO;
import com.fjwt.gz.service.activity.AbstractExportReport;
import com.fjwt.gz.service.impl.StatScoreRecordService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * ------ 福分明细记录报表导出
 * @author myf
 */
@Slf4j
@Service
public class ScoreRecordExportReport extends AbstractExportReport<StatScoreRecordVO> {

    @Autowired
    private StatScoreRecordService statScoreRecordService;



    private static final Map<String, String> HEADER_ALIAS_MAP = new HashMap<>();
    static {
        HEADER_ALIAS_MAP.put("fansId", "用户ID");
        HEADER_ALIAS_MAP.put("scoreRecordId", "福分记录id");
        HEADER_ALIAS_MAP.put("changeScore", "福分值");
        HEADER_ALIAS_MAP.put("changeCause", "生成原因");
        HEADER_ALIAS_MAP.put("changeTime", "生成时间");
        HEADER_ALIAS_MAP.put("changeType", "生成/扣除");
        HEADER_ALIAS_MAP.put("exchangeCoupons", "是否兑换福券");
        HEADER_ALIAS_MAP.put("baiFuEnter", "是否百福进门");
        HEADER_ALIAS_MAP.put("agentNo4", "网点机构号");
        HEADER_ALIAS_MAP.put("agentName4", "网点机构名称");
        HEADER_ALIAS_MAP.put("agentNo3", "区县机构号");
        HEADER_ALIAS_MAP.put("agentName3", "区县机构名称");
    }


    @Override
    public String exportActivityExcel(SysExportTaskEntity sysExportTaskEntity) {
        StatScoreRecordDTO scoreRecordDTO = getRequestParam(sysExportTaskEntity.getRequestParam(), StatScoreRecordDTO.class);
        List<StatScoreRecordVO> list = statScoreRecordService.selectExportScoreRecords(scoreRecordDTO);
        for (StatScoreRecordVO scoreRecordVO : list) {
            scoreRecordVO.setChangeType("ADD".equals(scoreRecordVO.getChangeType()) ? "生成" : "扣除");
            scoreRecordVO.setExchangeCoupons("EXCHANGE_COUPON".equals(scoreRecordVO.getTag()) ? "是" : "否");
            scoreRecordVO.setBaiFuEnter("BAI_FU_JIN_MEN".equals(scoreRecordVO.getTag()) ? "是" : "否");
        }
        return createExcelAndUploadOssUrl(list, HEADER_ALIAS_MAP, sysExportTaskEntity);
    }
}
